package org.fnzn.web.fngl;

import org.apache.log4j.Logger;
import org.fnzn.aop.SystemControllerLog;
import org.fnzn.bean.FnglStaff;
import org.fnzn.bean.vo.User;
import org.fnzn.core.Page;
import org.fnzn.core.Result;
import org.fnzn.service.FnglStaffService;
import org.fnzn.util.CommonUtil;
import org.fnzn.web.SysLogController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

/**
 * 人员信息管理
 */
@RestController
@RequestMapping(value = "/fnglStaff")
@EnableAutoConfiguration
public class FnglStaffController {
    Logger log = Logger.getLogger(SysLogController.class);
    
    @Autowired
    private FnglStaffService fnglStaffService;

    @RequestMapping(value = "/list",produces = "application/json;charset=UTF-8",method = RequestMethod.GET)
    @SystemControllerLog(description="查询人员")
    public Result findFnglStaff(FnglStaff fnglStaff, Page page){
        return fnglStaffService.findFnglStaff(fnglStaff,page);
    }

    @RequestMapping(value = "/add",produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @SystemControllerLog(description="新增人员")
    public Result insertFnglStaff(FnglStaff fnglStaff){
        return  fnglStaffService.insertFnglStaff(fnglStaff);
    }

    @RequestMapping(value = "/update",produces = "application/json;charset=UTF-8",method = RequestMethod.PUT)
    @SystemControllerLog(description="修改人员")
    public Result updateFnglStaff(FnglStaff fnglStaff){
        return  fnglStaffService.updateFnglStaff(fnglStaff);
    }

    @RequestMapping(value = "/{staffId}",produces = "application/json;charset=UTF-8",method = RequestMethod.DELETE)
    @SystemControllerLog(description="删除人员")
    public Result deleteFnglStaff(@PathVariable String staffId){
        return  fnglStaffService.deleteFnglStaff(staffId);
    }

    @RequestMapping(value = "/deleteAll",produces = "application/json;charset=UTF-8",method = RequestMethod.GET)
    @SystemControllerLog(description="删除多个人员")
    public Result deleteAllFnglStaff(String staffIds){
        return fnglStaffService.deleteAllFnglStaff(staffIds);
    }

    /**
     * 根据当前登录用户获取到销售人员列表
     */
    @RequestMapping(value = "/getStaff",produces = "application/json;charset=UTF-8",method = RequestMethod.GET)
    @SystemControllerLog(description="获取销售人员列表")
    public Result getStaff(){
        User user = CommonUtil.getUser();
        return fnglStaffService.getStaff(user);
    }

    /**
     *  获取到所有的项目经理
     */
    @RequestMapping(value = "/getManager",produces = "application/json;charset=UTF-8",method = RequestMethod.GET)
    @SystemControllerLog(description="获取项目经理列表")
    public Result getManager(){
        return fnglStaffService.getManager();
    }

    /**
     *  获取二手房下面的销售人员
     */
    @RequestMapping(value = "/getHouseStaff",produces = "application/json;charset=UTF-8",method = RequestMethod.GET)
    @SystemControllerLog(description = "获取到二手房下面的所有销售人员")
    public Result getHouseStaff(){
        return fnglStaffService.getHouseStaff();
    }

}
